package com.zr.eim.controller;

import com.zr.common.annotation.Anonymous;
import com.zr.common.annotation.Log;
import com.zr.common.core.controller.BaseController;
import com.zr.common.core.domain.AjaxResult;
import com.zr.common.core.page.TableDataInfo;
import com.zr.common.enums.BusinessType;
import com.zr.common.utils.poi.ExcelUtil;
import com.zr.eim.domain.EimAnalysisStayPoint;
import com.zr.eim.domain.EimDataPerson;
import com.zr.eim.service.IEimAnalysisStayPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 停留点信息Controller
 * 
 * @author peihang
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/eim/staypoint")
public class EimAnalysisStayPointController extends BaseController
{
    @Autowired
    private IEimAnalysisStayPointService eimAnalysisStayPointService;

    /**
     * 查询停留点信息列表
     */

    @GetMapping("/list")
    @Anonymous
    @PermitAll
    public TableDataInfo list(EimAnalysisStayPoint eimAnalysisStayPoint)
    {
        startPage();
        List<EimAnalysisStayPoint> list = eimAnalysisStayPointService.selectEimAnalysisStayPointList(eimAnalysisStayPoint);
        return getDataTable(list);
    }

    @PostMapping("/getStayPointByPersonId")
    @Anonymous
    @PermitAll
    public AjaxResult getStayPointByPersonId(EimDataPerson eimDataPerson)
    {
        EimAnalysisStayPoint list = eimAnalysisStayPointService.getStayPointByPersonId(eimDataPerson);
        return AjaxResult.success(list);
    }


    //   根据personID查询停留点
    @PreAuthorize("@ss.hasPermi('eim:staypoint:query')")
    @GetMapping("/person/{personId}")
    public AjaxResult listByPersonId(EimDataPerson eimDataPerson)
    {
        List<EimAnalysisStayPoint> list = eimAnalysisStayPointService.selectEimAnalysisStayPointByPersonId(eimDataPerson);
        return AjaxResult.success(list);
    }


    /**
     * 导出停留点信息列表
     */
    @PreAuthorize("@ss.hasPermi('eim:staypoint:export')")
    @Log(title = "停留点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EimAnalysisStayPoint eimAnalysisStayPoint)
    {
        List<EimAnalysisStayPoint> list = eimAnalysisStayPointService.selectEimAnalysisStayPointList(eimAnalysisStayPoint);
        ExcelUtil<EimAnalysisStayPoint> util = new ExcelUtil<EimAnalysisStayPoint>(EimAnalysisStayPoint.class);
        util.exportExcel(response, list, "停留点信息数据");
    }



    /**
     * 获取停留点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('eim:staypoint:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eimAnalysisStayPointService.selectEimAnalysisStayPointById(id));
    }

    /**
     * 新增停留点信息
     */
    @PreAuthorize("@ss.hasPermi('eim:staypoint:add')")
    @Log(title = "停留点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EimAnalysisStayPoint eimAnalysisStayPoint)
    {
        return toAjax(eimAnalysisStayPointService.insertEimAnalysisStayPoint(eimAnalysisStayPoint));
    }

    /**
     * 修改停留点信息
     */
    @PreAuthorize("@ss.hasPermi('eim:staypoint:edit')")
    @Log(title = "停留点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EimAnalysisStayPoint eimAnalysisStayPoint)
    {
        return toAjax(eimAnalysisStayPointService.updateEimAnalysisStayPoint(eimAnalysisStayPoint));
    }

    /**
     * 删除停留点信息
     */
    @PreAuthorize("@ss.hasPermi('eim:staypoint:remove')")
    @Log(title = "停留点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eimAnalysisStayPointService.deleteEimAnalysisStayPointByIds(ids));
    }
}
